<template>
  <div class="monitorTable">
    <ul class="tableColumns">
      <li class="listItem" v-for="(item, i) of state.columns" :key="i" :style="getColumnStyle(item)">
        {{ item.title }}
      </li>
    </ul>
    <vue3ScrollSeamless class="tableScrollWrap" :classOptions="{ step: 0.3 }" :dataList="state.dataSource">
      <ul class="listWrap" v-if="state.dataSource && state.dataSource.length > 0">
        <li class="listItem" v-for="(item, i) of state.dataSource" :key="i">
          <p
            v-for="(child, index) in state.columns"
            :key="index"
            :style="getColumnStyle(child)"
            :data-source="JSON.stringify(item)"
          >
            <template v-if="child.dataIndex === 'index'">
              {{i + 1}}
            </template>
            <template v-if="child.dataIndex === 'level'">
              <span class="level1" v-if="item.level == '1'">蓝色预警</span>
              <span class="level2" v-if="item.level == '2'">黄色预警</span>
              <span class="level3" v-if="item.level == '3'">红色预警</span>
            </template>
            <template v-else>{{ item[child.dataIndex] }}</template>
          </p>
        </li>
      </ul>
      <div class="emptyText" v-else>
        <a-empty :image="Empty.PRESENTED_IMAGE_SIMPLE" description="暂无预警"/>
      </div>
    </vue3ScrollSeamless>
  </div>
</template>

<script lang="ts" setup>
  import { reactive, onMounted } from 'vue';
  import { Empty } from 'ant-design-vue';
  import { vue3ScrollSeamless } from "vue3-scroll-seamless";
  // import { getWaterWarningData } from '@/api/oneMap/baseData';
  import dayjs from "dayjs";

  defineOptions({ name: 'MonitorTable' });

  const state = reactive({
    loading: false,
    columns: [
      { title: '序号', dataIndex: 'index', key: 'index', width: '60px', align: 'center' },
      { title: '所属河流', dataIndex: 'name', key: 'name', align: 'center' },
      { title: '断面名称', dataIndex: 'dm', key: 'dm', align: 'center' },
      { title: '预报水位(mm)', dataIndex: 'z', key: 'z', align: 'center' },
      { title: '告警等级', dataIndex: 'level', key: 'level', align: 'center' },
    ],
    dataSource: [],
  });

  // 计算属性来动态计算样式
  const getColumnStyle = (column) => {
    return {
      width: column.width || `${(100 / state.columns.length)}%`
    };
  };

  const getTableDataSource = async ()=> {
    state.loading = true;
    state.dataSource = [
      { name: '上柳溪', dm: '断面名称信息', z: '5.65', level: '1' },
      { name: '上柳溪', dm: '断面名称信息', z: '5.65', level: '1' },
      { name: '上柳溪', dm: '断面名称信息', z: '5.65', level: '1' },
      { name: '上柳溪', dm: '断面名称信息', z: '5.65', level: '2' },
      { name: '上柳溪', dm: '断面名称信息', z: '5.65', level: '2' },
      { name: '上柳溪' , dm: '断面名称信息', z: '5.65', level: '1'},
      { name: '上柳溪', dm: '断面名称信息', z: '5.65', level: '1' },
      { name: '上柳溪', dm: '断面名称信息', z: '5.65', level: '3' },
      { name: '上柳溪', dm: '断面名称信息', z: '5.65', level: '3' },
      { name: '上柳溪', dm: '断面名称信息', z: '5.65', level: '3' },
      { name: '上柳溪', dm: '断面名称信息', z: '5.65', level: '1' },
    ];
    state.loading = false;
  }

  onMounted(async() => {
    getTableDataSource();
  });
</script>

<style lang="less" rel="stylesheet/less" scoped>
  .monitorTable {
    width: 100%;
    height: 94%;
    overflow: hidden;
    .tableColumns {
      width: 100%;
      height: 26px;
      font-size: 12px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-bottom: 1px solid  rgba(220, 237, 255, 0.2);
      background: #026EC261;
      position: relative;
      margin-bottom: 6px;
      &::before {
        content: '';
        width: 2px;
        height: 10px;
        background: #D7EEFF;
        position: absolute;
        left: 0px;
        opacity: 0.8;
      }
      &::after {
        content: '';
        width: 2px;
        height: 20px;
        background: #D7EEFF;
        position: absolute;
        right: 0px;
        opacity: 0.8;
      }
      li {
        width: 100%;
        padding: 8px 8px;
        font-size: 12px;
        text-align: center;
        color: #D7EEFF;
        position: relative;
        &::after {
          content: '';
          width: 0;
          height: 0;
          display: inline-block;
          border-left: 4px solid transparent;
          border-right: 4px solid transparent;
          border-top: 4px solid #06B7FD;
          position: absolute;
          bottom: 4px;
          left: 50%;
          transform: translateX(-50%);
        }
      }
    }
    .tableScrollWrap {
      width: 100%;
      height: calc(100% - 24px);
      min-height: 150px !important;
      overflow: hidden;
      overflow-y: auto;
      &::-webkit-scrollbar {
        width: 0;
        height: 0;
      }
      ul.listWrap {
        width: 100%;
        height: 100%;
        overflow: hidden;
        overflow-y: auto;
      }
      li.listItem {
        width: 100%;
        min-height: 26px;
        margin-bottom: 8px;
        /* border: 1px solid #DCEDFF4D;
        background: #026EC21F; */
        background: url(./table_bg.png) no-repeat;
        background-size: 100% 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        color: #fff;
        padding: 0 10px;
        p {
          width: 100%;
          color: #fff;
          text-align: center;
          font-size: 12px;
        }
        &:hover {
          background: url(./table_bg_a.png) no-repeat;
          background-size: 100% 100%;
          cursor: pointer;
        }
        .level1 {
          display: inline-block;
          width: 100px;
          font-size: 12px;
          text-align: center;
          background: linear-gradient(90deg, rgba(0, 83, 218, 0.6) 0%, rgba(6, 183, 253, 0.6) 100%);
          border: 1px solid;
          border-image: linear-gradient(90deg, #06B7FD 0%, rgba(255, 255, 255, 0.85) 46.88%, #06B7FD 100%);
          border-image-slice: 1;
        }
        .level2 {
          display: inline-block;
          width: 100px;
          font-size: 12px;
          text-align: center;
          background: linear-gradient(90deg, rgba(255, 199, 0, 0.67) 0%, rgba(253, 216, 46, 0.47) 100%);
          border: 1px solid;
          border-image: linear-gradient(90.61deg, #FDD82E 0.52%, #FFFFFF 48.51%, #FDD82E 99.59%);;
          border-image-slice: 1;
        }
        .level3 {
          display: inline-block;
          width: 100px;
          font-size: 12px;
          text-align: center;
          background: linear-gradient(90deg, rgba(255, 92, 0, 0.6) 0%, rgba(255, 48, 54, 0.6) 97.22%);
          border: 1px solid;
          border-image: linear-gradient(90deg, #FF3036 0%, rgba(255, 255, 255, 0.72) 48.62%, rgba(255, 48, 54, 0.96) 100%);
          border-image-slice: 1;
        }
      }
      ::v-deep(.ant-empty-description) {
        color: #fff;
      }
    }
    .action1 {
      color: #51FBFF
    }
    .action2 {
      color: #FF3036;
    }
    .result2 {
      color: #FF8A00;
    }
  }
</style>
